package org.harsh.transmission.common.codec;

import cn.hutool.core.codec.Base64;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;
import org.harsh.transmission.common.ITransable;

/**
 * Created by liuhaibo on 2024/6/12.
 */
@Slf4j
public class MsgPackEncoder extends MessageToByteEncoder<ITransable> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, ITransable msg, ByteBuf byteBuf) throws Exception {
//        log.info("MsgPackEncoder encode:{}", msg);
        byte[] tmp = msg.buildBytes();
//        log.info("Send File Str: {}", Base64.encode(tmp));
        byteBuf.writeBytes(tmp);
    }
}
